<template>
    <div class="search-row">
        <div class="search-label">办件查询</div>
        <div class="input-row">
            <input v-model="keywords" placeholder="请输入企业名称/手机号码/办理事项..." type="text">
            <div class="search-btn-row">
                <button @click="reset" class="reset-btn">重置</button>
                <button @click="search" class="search-btn">
                    <img src="../../assets/search.png" alt="">
                </button>
            </div>
        </div>
        <SearchDialog v-on:onPager="onPager" v-bind:total="total" v-bind:list="searchList" />
    </div>
</template>

<script>
import SearchDialog from "./searchDialog.vue"; //查询办件弹窗
import Pubsub from "../../utils/pubsub";
import { searchWorkbenchList } from "../../config/api";
import { Message } from "element-ui";

export default {
    components: {
        SearchDialog
    },
    data() {
        return {
            keywords: "",
            searchList: [],
            total: 0
        };
    },
    methods: {
        //搜索
        
        search(req) {
            if (!this.keywords) {
                return;
            }
            let defaultRequest = {
                pageNum: 1,
                pageSize: 7,
                keyword: this.keywords
            };

            let request = Object.assign(defaultRequest, req);
            searchWorkbenchList(request).then((result = {}) => {
                let { rows = [] } = result;
                if (rows.length) {
                    this.searchList = rows;
                    Pubsub.publish("showSearchDialog");
                } else {
                    Message.warning("没有查询到相关信息，请重新查询");
                }
                this.total = result.total;
            });
        },
        /**
         * 重置
         */
        reset() {
            this.keywords = "";
        },
        onPager(e) {
            this.search({ pageNum: e });
        }
    }
};
</script>

<style lang="scss" scoped>
.search-label {
    height: 58px;
    width: 150px;
    background: #004293;
    color: #fff;
    margin-right: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}
.input-row {
    flex: 1;
    display: flex;
    position: relative;
    input {
        flex: 1;
        font-size: 16px;
        padding-left: 20px;
        padding-right: 145px;
    }
    .search-btn-row {
        position: absolute;
        display: flex;
        align-items: center;
        right: 0;
    }
    .reset-btn {
        color: #c13530;
        padding: 20px;
        opacity: 0.8;
    }
    .search-btn {
        background: #822424;
        height: 57px;
        padding: 0 12px;
        &:active {
            opacity: 0.8;
        }
    }
}
</style>